<div class="header_menu">
    <div class="container">
        <div class="header-nav clearfix">
            <?php echo $this->partial('site/headermenu'); ?>
        </div>
    </div>
</div>
</div>

<div class="container">
    <div class="xm-plain-box">
        <div class="box-hd">
            <h3 class="title"><?php echo $this->translate('重置密码'); ?></h3>
        </div>
        <div class="box-bd">
            <div class="row">
                <?php
                if (isset($this->message) and $this->message != '') {
                    echo '<h4>' . $this->message . '</h4>';
                } elseif(isset($this->step) and $this->step == 2){ ?>
                    <form name="forgot_form" id="forgot_form" method="post" class="form-horizontal" action="<?php echo $this->url('frontuser/default',array('action'=>'phoneforgotpasswdedit')); ?>">
                        <input type="hidden" name="step" value="step3">
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('用户名称'); ?>：</label>
                            <div class="controls">
                                <input type="text" class="span3" disabled value="<?php echo $this->escapeHtml($this->user_name); ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('手机号码'); ?>：</label>
                            <div class="controls">
                                <input type="text" class="span3" disabled value="<?php echo $this->escapeHtml($this->user_phone); ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('手机验证码'); ?>：</label>
                            <div class="controls">
                                <input type="text" class="span1" name="phone_code" id="phone_code" value="">
                                <input type="button" class="btn btn-primary btn-small" id="get_phone_code" value="<?php echo $this->translate('发送手机验证码'); ?>">
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="controls">
                                <button class="btn btn-primary" type="submit"><?php echo $this->translate('下一步'); ?></button>
                            </div>
                        </div>
                    </form>
                <?php } else { ?>
                    <form name="forgot_form" id="forgot_form" method="post" class="form-horizontal" action="">
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('重置方式'); ?>：</label>
                            <div class="controls">
                                <?php echo $this->translate('手机号码'); ?>
                                &nbsp;&nbsp;<a href="<?php echo $this->url('frontuser/default',array('action'=>'forgotpasswd')); ?>" class="btn"><?php echo $this->translate('点击通过电子邮箱重置'); ?></a>
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('手机号码'); ?>：</label>
                            <div class="controls">
                                <input type="text" id="user_phone" class="span3" placeholder="<?php echo $this->translate('输入注册时的手机号码'); ?>" name="user_phone">
                            </div>
                        </div>
                        <div class="control-group">
                            <label for="input01" class="control-label"><?php echo $this->translate('验证码'); ?>：</label>
                            <div class="controls">
                                <input type="text" class="input-small" id="captcha_code" name="captcha_code" placeholder="<?php echo $this->translate('输入验证码'); ?>">&nbsp;<span id="forgot_captcha_id"></span>
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="controls">
                                <button class="btn btn-primary" type="submit"><?php echo $this->translate('下一步'); ?></button>
                            </div>
                        </div>
                    </form>

                <?php } ?>
            </div>
        </div>
    </div>
</div>
<script>
    <?php if(isset($this->step) and $this->step == 2){ ?>
    $(document).ready(function() {
        $("#forgot_form").validate({
            success : function(label){
                label.addClass('validate_right').text('OK!');
            },
            rules: {
                phone_code: {
                    required:true,
                    remote :{
                        url : '<?php echo $this->url('frontuser/default',array('action'=>'sendPhoneCode'), array('query'=>array('type'=>'checkphonecode'))); ?>',
                        type : 'post',
                        date : {
                            captcha_code :function(){
                                return $("#phone_code").val();
                            }
                        }
                    }
                }
            },
            messages: {
                phone_code: {
                    required:"<?php echo $this->translate('手机验证码不能为空！'); ?>",
                    remote : "<?php echo $this->translate('验证码错误！'); ?>"
                }
            }
        });
    });

    var waittime = 60;
    function captchatime() {
        if (waittime == 0) {
            $('#get_phone_code').removeAttr("disabled");
            $('#get_phone_code').val('<?php echo $this->translate('发送验证码'); ?>');
            waittime = 60;
        }
        else {
            $('#get_phone_code').val("<?php echo $this->translate('重新发送'); ?>(" + waittime + ")");
            waittime--;
            setTimeout(function() {
                    captchatime()
                },
                1000)
        }
    }
    document.getElementById("get_phone_code").onclick=function(){
        $.ajax({
            type : 'POST',
            url	 : '<?php echo $this->url('frontuser/default',array('action'=>'sendPhoneCode')); ?>',
            success: function(msg){
                if(msg != '') {
                    alert(msg);
                    return false;
                } else {
                    $('#get_phone_code').attr("disabled", true);
                    captchatime();
                }
            }
        });
    }
    <?php } else { ?>
    $(document).ready(function() {
        $("#forgot_form").validate({
            success : function(label){
                label.addClass('validate_right').text('OK!');
            },
            rules: {
                user_phone: {
                    required: true,
                    isMobile: true
                },
                captcha_code: {
                    required:true,
                    remote :{
                        url : '<?php echo $this->url('shopfront/default/captcha-check',array('action'=>'captcha','captcha_check'=>1)); ?>',
                        type : 'post',
                        date : {
                            captcha_code :function(){
                                return $("#captcha_code").val();
                            }
                        }
                    }
                }
            },
            messages: {
                user_phone: {
                    required: "<?php echo $this->translate('手机号码不能为空！'); ?>",
                    isMobile: "<?php echo $this->translate('请填写正确的手机号码！'); ?>"
                },
                captcha_code: {
                    required:"<?php echo $this->translate('验证码不能为空！'); ?>",
                    remote : "<?php echo $this->translate('验证码错误！'); ?>"
                }
            }
        });
    });
    //验证码添加
    function captchaAdd() {
        $.get("<?php echo $this->url('shopfront/default',array('action'=>'captcha')); ?>",{},
            function(data){
                $("#forgot_captcha_id").html('<img src="<?php echo $this->basePath('/'); ?>'+data.captcha_file+'" border="0" >&nbsp;&nbsp;<a href="javascript:;" onclick="captchaAdd()"><?php echo $this->translate('更换验证码'); ?></a>');
            },'json');
    }
    captchaAdd();
    <?php } ?>
</script>